Part Number Hot Search : 
10011 SIP5630 UDA1380 SK373 G13JVF AD579T 7N60C3 19N502
Product Description
Full Text Search
 

To Download AN2834 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  september 2013 docid15067 rev 2 1/45 AN2834 application note how to get the best adc accu racy in stm32fx series and stm32l1 series devices introduction the stm32fx series and stm3 2l1 series microcon troller families em bed up to four advanced 12-bit adcs (depending on the device). a self-calibration fe ature is provided to enhance adc accuracy versus environmental condition changes. in applications involving analog-to-digital co nversion, adc accuracy has an impact on the overall system quality and efficiency. to improve this accuracy, you need to understand the errors associated with the adc an d the parameters affecting them. adc accuracy does not depend on adc performanc e and features alone, it depends on the overall application design around the adc. this application note aims to help underst anding of adc errors and how to enhance adc accuracy. it is divided into three main parts: ? a simplified description of adc internal stru cture to aid understand ing of adc operation and related adc parameters ? explanations of the different types and sources of adc errors related to the adc design and to external adc parameters such as the external hardware design ? recommendations on how to minimize these errors, focusing on hardware and software methods this document applies to the products listed in table 1 which are referred to as stm32x throughout this document. table 1. applicable products product family part numbers microcontrollers ? stm32f0xx ? stm32f1xx ? stm32f2xx ? stm32f3xx ? stm32f4xx ? stm32l1xx www.st.com
contents AN2834 2/45 docid15067 rev 2 contents 1 adc internal principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.1 sar adc internal structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2 adc errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.1 adc errors related to the adc itself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.1.1 offset error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.1.2 gain error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2.1.3 differential linearity error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.1.4 integral linearity error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.1.5 total unadjusted error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.2 adc errors related to its environment . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.2.1 reference voltage noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.2.2 reference voltage / power supply regulati on . . . . . . . . . . . . . . . . . . . . . 15 2.2.3 external reference voltage parameters . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.2.4 analog input signal noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.2.5 adc dynamic range bad match for maximum input signal amplitude . . 16 2.2.6 effect of the analog signal source resistance . . . . . . . . . . . . . . . . . . . . 16 2.2.7 effect of source capacitance and pa rasitic capacitance of the pcb . . . 17 2.2.8 injection current effect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.2.9 temperature influence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.2.10 i/o pin crosstalk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.2.11 emi-induced noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3 how to get the best adc accur acy . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 3.1 reduce the effects of adc-related adc errors . . . . . . . . . . . . . . . . . . . . 20 3.2 minimize adc errors related to external environment of adc . . . . . . . . . 20 3.2.1 reference voltage / power supply noise minimization . . . . . . . . . . . . . 20 3.2.2 reference voltage / power-supply regulation . . . . . . . . . . . . . . . . . . . . 22 3.2.3 analog-input signal noise elimination . . . . . . . . . . . . . . . . . . . . . . . . . . 22 3.2.4 adding white noise or triangular swee p to improve resolution . . . . . . . . 22 3.2.5 matching the adc dynamic range to the maximum signal amplitude . . 23 3.2.6 analog source resistance calculation . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.2.7 source frequency condition vs. source and parasitic capacitors . . . . . . 27 3.2.8 temperature-effect compensati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
docid15067 rev 2 3/45 AN2834 contents 3 3.2.9 minimizing injection current . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.2.10 minimizing i/o pin crosstalk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.2.11 emi-induced noise reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.2.12 pcb layout recommendations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.2.13 component placement and routing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 3.3 software methods to improve precision . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.3.1 averaging samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.3.2 digital signal filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.3.3 fft for ac measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3.3.4 adc calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 3.3.5 minimizing internal cpu noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 3.4 high impedance source measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 3.4.1 adc input stage problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 3.4.2 explanation of the behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 3.4.3 minimizing added errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 3.4.4 source of described problem - adc design . . . . . . . . . . . . . . . . . . . . . 41 4 conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 5 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
list of figures AN2834 4/45 docid15067 rev 2 list of figures figure 1. basic schematic of sar s witched-capacitor adc (example for 10-bit adc) . . . . . . . . . . . . 5 figure 2. sample state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 figure 3. hold state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 figure 4. step 1: compare with vref/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 figure 5. step 2: if msb = 1, then compare with ? vref. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 figure 6. step 2: if msb = 0, then compare with ? vref. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 figure 7. positive offset error representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 figure 8. negative offset error representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 figure 9. positive gain error representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 figure 10. negative gain error representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 figure 11. differential linearity error representation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 figure 12. integral linearity error represen tation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 figure 13. total unadjusted error. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 figure 14. input signal amplitude vs. adc dynamic range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 figure 15. analog signal source resistance effect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 figure 16. analog input with r ain , c ain and c p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 figure 17. effect of injection current . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 figure 18. crosstalk between i/o pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 figure 19. emi sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 figure 20. power supply and reference decoupling for 10 0- and 144-pin packages . . . . . . . . . . . . . . 21 figure 21. power supply decoupling for 36-, 48- and 64-pin packages . . . . . . . . . . . . . . . . . . . . . . . . 21 figure 22. simple quasi-triangular source using a microcont roller output . . . . . . . . . . . . . . . . . . . . . . 23 figure 23. selecting the reference voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 figure 24. preamplification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 figure 25. worst case error: v ain = v ref+. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 figure 26. recommended values for r ain and c ain vs. source frequency f ain . . . . . . . . . . . . . . . . . . . . . . 27 figure 27. crosstalk between i/o pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 figure 28. shielding technique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 figure 29. separating the analog and digital layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 figure 30. separating the analog and digital supplies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 0 figure 31. typical voltage source connection to adc input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 figure 32. noise observed on adc input pin during adc conv ersions . . . . . . . . . . . . . . . . . . . . . . . . 35 figure 33. adc simplified schematic of i nput stage - sample and hold circuit. . . . . . . . . . . . . . . . . . . 36 figure 34. adc input pin noise spikes from internal ch arge during sampling process . . . . . . . . . . . . 36 figure 35. effect of sampling time extension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 figure 36. charging the external capacitor with too shor t time between conversions . . . . . . . . . . . . . 38 figure 37. implementation of sampling switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 figure 38. parasitic capacitances of sampling switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1 figure 39. parasitic current example inside adc structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
docid15067 rev 2 5/45 AN2834 adc internal principle 44 1 adc internal principle 1.1 sar adc internal structure the adc in stm32x microcontrollers uses the sar (successive approximation register) principle, by which the conversion is performe d in several steps. the number of conversion steps is equal to the number of bits in the a dc converter. each step is driven by the adc clock. each adc clock produces one bit from result to output. adc internal design is a switched-capacitor type. the following figures ( figure 1 to figure 6 ) explain the principle of adc operation. the example given below shows only the first steps of approximation but the process continues till the lsb is reached. figure 1. basic schematic of sar switched-capacitor adc (example for 10-bit adc) 1. basic adc schematic with digital output. s1 sb clk d q clr pr a s2 sa v in adc data adc clk s3 s4 s5 s6 s7 s8 s9 c c/2 c/4 c/8 c/16 c/32 c/64 c/128 c/256 ai17097 v ref s10 s11 c/512 c/512
adc internal principle AN2834 6/45 docid15067 rev 2 figure 2. sample state 1. sample state - capacitors are charging to v in voltage. sa switch to v in , sb switch closed during sampling time. figure 3. hold state 1. hold state - input is disconnected - capacitors hold i nput voltage. sb switch is open, then s1-s11 switched to ground and sa switched to v ref . s1 sb clk d q clr pr a s2 sa v in adc data adc clk s3 s4 s5 s6 s7 s8 s9 c c/2 c/4 c/8 c/16 c/32 c/64 c/128 c/256 ai17098 v ref s10 s11 c/512 c/512 a 2c v comp = 0 equivalent circuit: v in s1 sb clk d q clr pr a s2 sa v in adc data adc clk s3 s4 s5 s6 s7 s8 s9 c c/2 c/4 c/8 c/16 c/32 c/64 c/128 c/256 ai17099 v ref s10 s11 c/512 c/512 equivalent circuit: a 2c v comp = Cv in
docid15067 rev 2 7/45 AN2834 adc internal principle 44 figure 4. step 1: compare with v ref /2 1. first approximation step. s1 switched to v ref . figure 5. step 2: if msb = 1, then compare with ? v ref 1. compare with ?v ref ; if msb =1. s1 switched back to ground. s2 switched to v ref . s1 sb clk d q clr pr a s2 sa v in adc data adc clk s3 s4 s5 s6 s7 s8 s9 c c/2 c/4 c/8 c/16 c/32 c/64 c/128 c/256 ai17800 v ref s10 s11 c/512 c/512 equivalent circuit: a c c v ref v comp = Cv in + v ref /2 s1 sb clk d q clr pr a s2 sa v in adc data adc clk s3 s4 s5 s6 s7 s8 s9 c c/2 c/4 c/8 c/16 c/32 c/64 c/128 c/256 ai17801 v ref s10 s11 c/512 c/512 equivalent circuit: a 3c/2 c/2 v ref v comp = Cv in + ? v ref
adc internal principle AN2834 8/45 docid15067 rev 2 figure 6. step 2: if msb = 0, then compare with ? v ref 1. compare with ? v ref ; if msb =0. s1 remained switched to ground. s2 switched to v ref . s1 sb clk d q clr pr a s2 sa v in adc data adc clk s3 s4 s5 s6 s7 s8 s9 c c/2 c/4 c/8 c/16 c/32 c/64 c/128 c/256 ai17802 v ref s10 s11 c/512 c/512 equivalent circuit: a c/2 3c/2 v ref v comp = Cv in + ? v ref
docid15067 rev 2 9/45 AN2834 adc errors 44 2 adc errors this section lists the main errors which have an effect on a/d conversion accuracy. these types of error occur in all a/d converters a nd conversion quality depends on eliminating them. values for these errors are specified in the adc characteristics section of the stm32x device datasheets. different accuracy error types are specified for the stm32x adc. accuracy errors are normally expressed as multiples of 1 lsb for easy reference. the re solution in terms of voltage depends on the reference voltage. the error in terms of voltage is calculated by multiplying the number of lsbs with the voltage corresponding to 1lsb (1lsb = v ref+ /2 12 or v dda /2 12 ). 2.1 adc errors related to the adc itself 2.1.1 offset error it is defined as the deviation betw een the first actual transition and the first ideal transition. the first transition occurs when the digital output of the adc changes from 0 to 1. ideally, when the analog input is between 0.5 lsb and 1.5lsb, the digital output should be 1. ideally still, the first transition occurs at 0.5 lsb. the offset error is denoted by e o . offset error can easily be calibrated by the application firmware. example for the stm32x adc, the smalle st detectable incremental change in voltage is expressed in terms of lsbs: 1 lsb = v ref+ /4096 (on some packages is v ref+ = v dda ). if v ref+ = 3.3 v, ideally, the input of 402.8 v (0.5 lsb = 0.5 805.6 v) should lead to the generation of a digita l output of 1. in practice, however , the adc may still show the reading as 0. if a digital output of 1 is obtai ned from an analog input of 550 v, then: offset error = actual transition ? ideal transition e o = 550 v ? 402.8 v = 141.2 v e o = 141.2 v / 805.6 v = 0.17 lsb when an analog input voltage greater than 0.5l sb generates the first transition, the offset error is positive. figure 7 shows a positive offset error.
adc errors AN2834 10/45 docid15067 rev 2 figure 7. positive offset error representation when an analog input voltage of less than 0.5lsb generates the first transition, the offset error is negative. figure 8 shows a negative offset error. if the analog input voltage v ain = v ssa and the adc generates a nonzero digital output, the offset error is negative. this means that a n egative voltage generates the first transition. figure 8. negative offset error representation digital output v ain ai15475 ideal transfer curve actual transfer curve 0.5lsb e o > 0 0 1 2 digital output ai15476 ideal transfer curve actual transfer curve v ain 0.5lsb e o > 0 0 1 2
docid15067 rev 2 11/45 AN2834 adc errors 44 2.1.2 gain error gain error is defined as the deviation between the last actual transition and the last ideal transition. gain error is represented as e g . the last actual transition is the transition from ffeh to fffh. ideally, there should be a transition from ffeh to fffh, when the analog input is equal to v ref+ ? 0.5lsb. so for v ref+ = 3.3 v, the last ideal transition should be at 3.299597 v. if the adc provides the fffh reading for v ain < v ref+ ? 0.5lsb, then we have a negative gain error. example gain error e g = last actual transition ? ideal transition if v ref+ = 3.3 v and v ain = 3.298435 v generates a transition from ffe to fff then, e g = 3.298435 v ? 3.299597 v e g = ?1162 v e g = (?1162 v / 805.6 v) lsb = ?1.44 lsb if we do not get a full sca le reading (fffh) for v ain equal to v ref+ , the gain error is positive. this means that a voltage greater than v ref+ will cause the last transition. figure 9 shows a positive gain error and figure 10 , a negative gain error. figure 9. positive gain error representation figure 10. negative gain error representation v ain digital output ai15477 ideal transfer curve actual transfer curve e g > 0 4095 4094.5 lsb v ain digital output ai15478 ideal transfer curve actual transfer curve e g < 0 4095 4094.5 lsb
adc errors AN2834 12/45 docid15067 rev 2 2.1.3 differential linearity error the differential linearity error (dle) is defined as the maximum deviation between the actual and ideal steps. here ?ideal? is not used for the ideal transfer curve but for the resolution of the adc. the dle is denoted by e d . it is represented in figure 11 . e d = actual step width ? 1lsb ideally, an analog input voltage change of 1lsb should cause a change in the digital code. if an analog input voltage greater than 1lsb is required for a change in digital code, the adc has a differential linearity error. the dle th erefore corresponds to the maximum additional voltage that is required to change from one digital code to the next. the dle is also known as the differential non-linearity (dnl) error. example a given digital output should correspond to an analog input range. ideally, the step width should be 1lsb. let us assume that we get th e same digital output over an analog input voltage range of 1.9998 v to 2.0014 v, the step width will be 2.0014 v ? 1.9998 v = 1.6 mv. e d is thus the voltage difference between the higher (2.0014 v) and lower (1.9998 v) analog voltages less the voltage corresponding to 1lsb. figure 11. differential linearity error representation if v ref+ = 3.3 v, an analog input of 1.9998 v (9 b1h) can provide results varying between 9b0h and 9b2h. similarly, for an input of 2.0014 v (9b3h), the results may vary between 9b2h and 9b4h. ? thus, the total voltage variation corresponding to the 9b2h step is: 9b3h ? 9b1h, that is, 2.0014 v ? 1.9998v = 1.6 mv (1660 v) e d = 1660 v ? 805.6 v e d = 854.4 v e d = (854.4 v/805.6 v) lsb e d = 1.06 lsb let us assume that no voltag e greater than 2.0014 v will result in the 9b2h digital code. when the step width is less than 1lsb, e d is negative. v ain digital output ideal transfer curve actual transfer curve actual step width actual step width 1lsb e d > 0 1lsb e d < 0 ai15479
docid15067 rev 2 13/45 AN2834 adc errors 44 2.1.4 integral linearity error the integral linearity error is the maximum dev iation between any actual transition and the endpoint correlation line. the ile is denoted by e l . it is represented in figure 12 . the endpoint correlation line can be defined as the line on the a/d transfer curve that connects the first actual transition with the last actual transition. e l is the deviation from this line for each transition. the endpoint correlation line thus corresponds to the actual transfer curve and has no relation to the ideal transfer curve. the ile is also known as the integral non lineari ty error (inl). the ile is the integral of the dle over the whole range. figure 12. integral linearity error representation example if the first transition from 0 to 1 occurs at 550 v and the last transition (ffeh to fffh) occurs at 3.298435 v (gain error), then the lin e on the transfer curve connecting the actual digital codes 1h and fffh will be the endpoint correlation line. v ain digital output ai15480 actual transfer curve e l 4095 550 v 3.298435 v 2 1 0
adc errors AN2834 14/45 docid15067 rev 2 2.1.5 total unadjusted error the total unadjusted error (tue) is defined as the maximum deviation between the actual and the ideal transfer curves. it is a parameter th at specifies the total errors that may occur, causing maximum deviation between the ideal digi tal output and the actual digital output. it is the maximum deviation recorded between the ideal expected value and the actual value obtained from the adc for any input voltage. the tue is denoted by e t . it is represented in figure 13 . the tue is not the sum of e o , e g , e l , e d . the offset error affects the digital result at lower voltages whereas the gain error affects the digital output for higher voltages. example if v ref+ = 3.3 v and v ain = 2 v, the ideal result is 9b2h. but if, on conversion, we get the result 9b4h, the deviation may result from th e offset since the dle and ile errors occur simultaneously. tue = absolute (actual value ? ideal case value) = 9b4h ? 9b2h = 2h = 2lsb figure 13. total unadjusted error v ain digital output ai15481 ideal transfer curve actual transfer curve e t
docid15067 rev 2 15/45 AN2834 adc errors 44 2.2 adc errors related to its environment 2.2.1 reference voltage noise as the adc output is the ratio between the analog signal voltage and the reference voltage, any noise on the analog reference will cause a c hange in the converte d digital value. the v dda analog power supply is used on some packages as the reference voltage (v ref+ ) so the quality of this power supp ly has influence to adc error. for example, with an analog reference of 3.3 v (v ref+ = v dda ) and a 1 v signal input, the converted result is (1/3.3) 4095 = 4d9h but with a 40 mv peak-to-peak ripple in the analog reference, the converted value becomes (1/3.34) 4095 = 4cah (with v ref+ at its peak). error = 4d9 ? 4ca = 15 lsb the smps (switch-mode power supply) normally has internal fast-switching power transistors. this introduces high-frequency noise in the output. the swit ching noise is in the range of 15 khz to 1 mhz. 2.2.2 reference voltage / power supply regulation power supply regulation is very important for adc accuracy since the conversion result is the ratio of the analog input voltage to the v ref+ value. if the power supply output decreases when connected to v dda or v ref+ due to the loads on these inputs and to its output impedance, an error will be intro duced in the conversion result. ? , where n is the resolution of the adc (in our case n = 12). ? if the reference voltage changes, the digital result changes too. for example: if the supply used is a reference voltage of 3.3 v and v ain = 1 v, the digital output is: if the voltage supply provides a voltage equal to 3.292 v (after its output connection to v ref+ ), then: the error introduced by the voltage drop is: 4dc ? 4d9 = 3lsb . digital code v ain 2 n 1 ? ?? v ref+ --------------------------------- - = digital output 12 12 1 ? ?? ? 3.3 --------------------------------- - 4d9h == digital output 12 12 1 ? ?? ? 3.292 --------------------------------- - 4dch ==
adc errors AN2834 16/45 docid15067 rev 2 2.2.3 external reference voltage parameters in case of usage external source for reference voltage (on v ref+ pin) there are important parameters of this external re ference source. it is important to look at three reference voltage specifications: te mperature drift, voltage no ise, long term stability. 2.2.4 analog input signal noise small but high-frequency signal variation can re sult in big conversion errors during sampling time. this noise is generated by electrical de vices, for example, motors, engine ignition, power lines, and so on, and affects the source signal (for example a sensor) by adding an unwanted signal. as a consequence, the conv ersion results of the adc are not accurate. 2.2.5 adc dynamic range bad match for maximum input signal amplitude it is very important that the adc dynamic range matches the maximum amplitude of the signal to be converted to have the maximum a dc conversion precision. let us assume that the signal to be converted varies between 0 v to 2.5 v and that v ref+ is equal to 3.3 v. the maximum signal value converted by the adc is 3102 (2.5 v) as shown in figure 14 . in this case, there are 993 unused transitions (4095 ? 3102 = 993). this implies a loss in the converted signal accuracy. see section 3.2.5: matching the adc dynamic range to the maximum signal amplitude on page 23 for details on how to have the adc dynamic range matching the maximum input signal amplitude. figure 14. input signal amplitude vs. adc dynamic range 2.2.6 effect of the anal og signal source resistance the impedance of the analog signal source, or series resistance (r ain ), between the source and pin causes a voltage drop across it beca use of the current flowing into the pin. the charging of the internal sampling capacitor c adc is controlled by switches with resistance r adc . with the addition of source resistance (with r adc ), the time required to fully charge the hold capacitor increases. figure 15 shows the analog signal source resistance effect. the effective charging of c adc is governed by r adc + r ain , so the charging time constant becomes t c = (r adc +r ain ) c adc . if the sampling time is less th an the time required to fully charge the c adc through r adc + r ain (t s < t c ), the digital value converted by the adc is less than the actual value. 2.5 v (3102h) v ref+ = 3.3 v (4095h) t v unused adc transition range ai15499
docid15067 rev 2 17/45 AN2834 adc errors 44 figure 15. analog signal source resistance effect 1. t c is the time taken by the c adc capacitor to fully charge: v c = v ain (with max.1/2 lsb error) ? v c : capacitor (c adc ) voltage ? t c = (r adc + r ain ) c adc 2.2.7 effect of source capacitance a nd parasitic capacitance of the pcb when converting analog signals, it is necessar y to account for the capacitance at the source and the parasitic capacitance seen on the analog input pin (refer to figure 16 ). the source resistance and capacitance form an rc networ k and the adc conversion results may not be accurate unless the external capacitor (c ain + c p ) is fully charged to the level of the input voltage. the greater value of (c ain + c p ), the more limited the source frequency. the external capacitance at the source and the parasitic capacitance are denoted by c ain and c p , respectively. figure 16. analog input with r ain , c ain and c p stm32 r adc c adc v ssa ain x r ain v ain v c v ain v c t c t 12-bit adc ai15482 stm32 ain x r ain v ain ai15483 c ain c p source
adc errors AN2834 18/45 docid15067 rev 2 2.2.8 injection current effect a negative injection current on any analog pin (o r a closely positioned digital input pin) may introduce leakage current into the adc input. the worst case is the adjacent analog channel. a negative injection current is introduced when v ain < v ss , causing current to flow out from the i/o pin. this is illustrated in figure 17 . figure 17. effect of injection current 2.2.9 temperature influence the temperature has a major influence on a dc accuracy. mainly it leads to two major errors: offset error drift and gain error drift. those errors can be compensated in the microcontroller firmware (refer to section 3.2.8 for the temperature-compensation methods). 2.2.10 i/o pin crosstalk switching the i/os may induce some noise in the analog input of the adc due to capacitive coupling between i/os. crosstalk may be introduced by pcb tracks that run close to each other or that cross each other. internally switching digital signals and i/os in troduces high-frequency noise. switching high- sink i/os may induce some voltage dips in the power supply caused by current surges. a digital track that crosses an analog input track on the pcb may affect the analog signal (see figure 18 ). figure 18. crosstalk between i/o pins case 1: digital and analog signal tracks that pass close to each other. case 2: digital and analog signal tracks that cross each other on a different pcb side. stm32 injection current leakage current ain 0 v ain0 r ain0 ain 1 v ain < v ss v ssa ai15484 analog in digital i/o case 1 case 2 analog in digital i/o stm32 stm32 ai15485
docid15067 rev 2 19/45 AN2834 adc errors 44 2.2.11 emi-induced noise electromagnetic emissions from neighboring circuits may introduce high-frequency noise in an analog signal because the pcb tr acks may act like an antenna (see figure 19. ). figure 19. emi sources stm32 ai15486 electro- magnetic noise i/o coupled noise noise induced from pcb tracks internal noise adc
how to get the best adc accuracy AN2834 20/45 docid15067 rev 2 3 how to get the best adc accuracy 3.1 reduce the effects of adc-related adc errors the tue is not the sum of all the errors e o , e g , e l , e d . it is the maximum deviation that can occur between the ideal and actual digital values. it can result from one or more errors occurring simultaneously. as the ile is the integral of the dle, it can be considered as the indicator of the maximum error. do not add the dle and ile together to calculate the maximum error that may occur at any digital step. the maximum error values specified in the datasheet are the worst error values measured in laboratory test environment over the giv en voltage and temperature range (see device datasheet). the ile and dle are dependent on the adc design. it is difficult to calibrate them. they can be calibrated by the measured adc curve stored in the microcontroller memory but this needs calibration of each indivi dual device in final application. offset and gain errors can be easily compen sated using the stm32x adc self-calibration feature or by microcontroller firmware. 3.2 minimize adc errors related to external environment of adc 3.2.1 reference voltage / po wer supply noise minimization power supply side linear regulators have a better output in terms of noise. the mains must be stepped down, rectified and filtered, then fed to linear regula tors. it is highly recommended to connect the filter capacitors to the rectifier output. plea se refer to the datasheet of the used linear regulator. if you are using a switching power supply, it is recommended to have a linear regulator to supply the analog stage. it is recommended to connect capacitors with good high-frequency characteristics between the power and ground lines. that is, a 0.1 f and a 1 to 10 f capacitor should be placed close to the power source. the capacitors allow the ac signals to pass th rough them. the small-value capacitors filter high-frequency noise and the high-value capaci tors filter low-frequ ency noise. ceramic capacitors are generally available in small values (1 pf to 0.1 f) and with small voltage ratings (16 v to 50 v). it is recommended to place them close to the main supply (v dd and v ss ) and analog supply (v dda and v ssa ) pins. they filter the noise induced in the pcb tracks. small capacitors can react fast to cu rrent surges and discharge quickly for fast- current requirements. tantalum capacitors can also be used along with ceramic capacitors. to filter low-frequency noise, you can use high-value capacitors (10 f to 100 f), which are generally electrolytic. it is recommended to put them near the power source. ? to filter high-frequency noise, you can use a ferrite inductance in series with the power supply. this solution leads to very low (n egligible) dc loss unless the current is high
docid15067 rev 2 21/45 AN2834 how to get the best adc accuracy 44 because the series resistance of the wire is very low. at high frequencies, however, the impedance is high. stm32x side in most stm32x microcontrollers the v dd and v ss pins are placed close to each other. so are the v ref+ and v ssa pins. a capacitor can therefore be connected very close to the microcontroller with very sh ort leads. for multiple v dd and v ss pins, use separate decoupling capacitors. the v dda pin must be connected to two external decoupling capacitors (10 nf ceramic + 1 f tantalum or ceramic). see figure 20 and figure 21 for decoupling examples. for stm32x devices delivered in 100/144-pin packages, it is possible to improve the accuracy on low-voltage inputs by connecting a separate external adc reference voltage input on v ref+ (refer to section 3.2.5 ). the voltage on v ref+ may range from 2.4 v to v dda . if a separate, external reference voltage is applied on v ref+ , two 10 nf and 1 f capacitors must be connected on this pin. in all cases, v ref+ must be kept between 2.4 v and v dda . figure 20. power supply and reference decoupling for 100- and 144-pin packages figure 21. power supply decoupling for 36-, 48- and 64-pin packages 1 f // 10 nf 1 f // 10 nf 1 f // 10 nf v dda v dda v ref+ v ref+ v refC v refC v ssa v ssa v ref+ not connected to v dda v ref+ connected to v dda ai15487 1 f // 10 nf v dda v ssa ai15488
how to get the best adc accuracy AN2834 22/45 docid15067 rev 2 3.2.2 reference voltage / power-supply regulation the power supply should have good line and load regulation since the adc uses v ref+ or v dda as the analog reference and the digital valu e is the ratio of the analog input signal to this voltage reference. v ref+ must thus remain stable at different loads. whenever the load is increased by switching on a part of the circuit, the increase in current must not cause the voltage to decrease. if the voltage remains stable over a wide current range, the power supply has good load regulation. for example: for the ld1086d2m33 voltage regulator, the line regulation is 0.035% typical when v in varies from 2.8 v to 16.5 v (when i load = 10 ma), and the load regulation is 0.2% when i load varies from 0 to 1.5 a (please refer to the ld1086 series datasheet for details). the lower the line regulation value, the better the regulation. similarly, the lower the load regulation value, th e better the re gulation and the stability of the voltage output. it is also possible to use a reference voltage for v ref+ , for instance the lm236, which is a voltage reference diode of 2.5 v (refer to lm236 datasheet for more details). 3.2.3 analog-input si gnal noise elimination averaging method averaging is a simple technique where you sample an analog input several times and take the average of the results by software. this technique is helpful to eliminate the effect of noise on the analog input in case of an analog voltage that does not change often. the average has to be made on several readings that all correspond to the same analog input voltage. make sure that the analog input remains at the same voltage during the time period when the conversions are done, otherwise you w ill add up digital values corresponding to different analog inputs, and you will introduce errors. adding an external filter adding an external rc filter eliminates the high frequency. an expensive filter is not needed to deal with a signal that has frequency com ponents above the frequency range of interest. in this case, a relatively simple lo wpass filter with a cutoff frequency f c just above the frequency range of intere st will suffice to limit noise and a liasing. a sampling rate consistent with the highest frequ ency of interest will suffice, typically 2 to 5 times f c . note: the r and c that form the external filter should have values that match the conditions described in section 3.2.4 and section 3.2.7 . 3.2.4 adding white noi se or triangular sweep to improve resolution this method combines hardware and software techniques to improve precision. from a software point of view, this method uses averaging (oversampling) and from a hardware point of view, it uses signal modification/spreading/dithering. averaging can be used in cases where the inpu t signal is noisy (some signal change is necessary in order to be able to calculate an average) and the requirement is to obtain the mean value of a signal. a problem appears when the input signal is a very stable voltage without noise. in this case, when the input si gnal is measured, each data sample is the same. this is because the input signal leve l is somewhere between two adc word levels (e.g. between 0x14a and 0x14b). therefore it is not possible to determine the input voltage level more precisely (e.g. if the level is near to 0x14a or near to 0x14b level).
docid15067 rev 2 23/45 AN2834 how to get the best adc accuracy 44 the solution is to add noise or some signal change (with uniform signal distribution e.g. triangular sweep) to the input signal which pushes its level across 1-bit adc level (so that the signal level changes below 0x14a and above 0x14b level). this causes the adc results to vary. applying software averaging to the different adc results, produces the mean value of the original input signal. example of implementation of this method is done by using a triangular generator with rc coupling to the input signal (white noise gener ation is more complicat ed). care must be taken not to modify the mean value of the original input signal (so, capacitive coupling must be used). a very simple implementation of the quasi-triang ular source which is generated directly by the stm32x microcontroller is on figure 22 . figure 22. simple quasi-triangular source using a microcontroller output 3.2.5 matching the adc dynamic range to the maximum signal amplitude this method improves accuracy by a proper sele ction of the reference voltage or by using a preamplifier stage to obtain the maximum possi ble resolution using the full adc output range. selecting a reference voltage (method for devices delivered in 100-/144-pin packages only) the reference voltage is selected in the expected range of the signal to be measured. if the measured signal has an offset, then the referenc e voltage should also have a similar offset. if the measured signal has a defined maximum am plitude, then the reference voltage should also have a similar maximum value. by matching this reference voltage to the measurement signal range, we obtain the maximum possible resolution using the full adc output range. in stm32x devices delivered in 100- and 144 -pin packages, the adc reference voltage is connected to the external v ref+ and v ref- pins that should be tied to ground. this makes it possible to match the reference voltage and the measured signal range. for example, if the measured signal varies between 0 v and 2.5 v, it is recommended to choose v ref+ = 2.5 v, possibly using a reference voltage like lm235 (see lm235 datasheet for more details). figure 23 illustrates these conditions. c r2 vin mcu ain out v dd t vin uin t uout r1 ai170803
how to get the best adc accuracy AN2834 24/45 docid15067 rev 2 note: the voltage on v ref+ may range between 2.4 v and v dda . figure 23. selecting the reference voltage using a preamplifier if the measured signal is too small (in comparison with the adc range) then it is good to use an external preamplifier. this method ca n be implemented with stm32x devices delivered in all packages, and more sp ecifically so in packages that do not have the v ref+ input. for example, if the measured signal varies between 0 v to 1 v and v dda is 3 v, the signal can be amplified so that its peak-to- peak amplitude is similar to the v dda value. the gain will then be equal to 3. figure 24 illustrates this example. this amplifier can adapt the input signal range to the adc range. it can also insert offsets between the input signal and the adc input. care must be taken in the preamplifier design not to generate additi onal errors (for exam ple additional offset, am plifier gain stability, linearity, frequency response, etc.). figure 24. pr eamplification t t digital output 4095 2.5 ------------ - v in  = digital output 4095 3.3 ------------ - v in  = 2.5 v (3102h) v ref+ = 3.3 v (4095h) v unused adc transition range v ref+ = 2.5 v (4095h) v change v ref+ value from 3.3 v to 2.5 v ai15600 t t digital output 4095 3 v in  = digital output 4095 3 ------------ - v in  = 1 v (1365h) v dda = 3 v (4095h) v unused adc transition range input signal max value is 3 v (4095h) v g = 3 ai15601 before amplification  g after amplification
docid15067 rev 2 25/45 AN2834 how to get the best adc accuracy 44 3.2.6 analog source resistance calculation let us assume that the maximu m error allowed is equal to 1/2 lsb. we will calculate the maximum source resistance allowed. v c is the voltage across the internal c adc capacitor (refer to figure 15 ). then we have: figure 25. worst case error: v ain = v ref+ let t s be the sampling time. t s = t s /f adc , where t s is the sampling time evaluated by cycles (1) for a given t s , the error corresponding to v ain = v ref+ is greater than the error corresponding to v ain < v ref+ because the c adc capacitor takes more time to charge from 0 v to v ain when v ain = v ref+ than it takes when v ain < v ref+ (refer to figure 25 ). so v ain = v ref+ is the worst case to be taken into a ccount in the demonstration of the maximum source resistance. ? , where: ? ? r max = (r ain + r adc )max (2) ? n is the adc resolution (in our case n = 12) ? ? this gives: . thus: (3) ? by combining equations (1), (2) and (3), we obtain final formula: error v ain v c ? 1 2 -- - lsb == v ain = v ref+ v ain < v ref+ error(v ain = v ref+ ) > error(v ain < v ref+ ) 0 v v c t error(v ain < v ref+ ) ai15602 error(v ain = v ref+ ) t s error v ref+ v ref+ 1e t s r max c adc ------------------------------- - ? ? ?? ?? ?? ?? ?? ?? ? 1 2 -- - v ref+ 2 n ------------------ - ? == e t s r max c adc ------------------------------- - ? 1 2 n1 + ---------- - = r max t s c adc 2 n1 + ?? ln ? ----------------------------------------- - = r ainmax t s f adc c adc 2 n1 + ?? ln ?? ------------------------------------------------------------------- r adcmax ? =
how to get the best adc accuracy AN2834 26/45 docid15067 rev 2 example for stm32f1 parameters: ? f adc = 14 mhz, c adc = 8 pf, r adc max = 1 k ? and for t s = 7.5, the maximum source resistance allowed for an error equal to 1/2 lsb is: ? ? ? that is: note: the use of a follower amplifie r can reduce the resistance of the source effect because of its high input impedance and its very low output impedance. it isolates r ain from r adc . however, the amplifier introdu ces an offset error that s hould be taken into account. in case of longer sampling times and reduced number of adc clocks, better results can be obtained. it is possible to further increase the allowed external resistance by decreasing the adc clock frequency or selectin g a lower resolution. refer to the datasheet of your device to obtain the exact values of the rc parameters. r ainmax 7.5 14 10 6 810 12 ? 2 12 1 + ?? ln ??? ? ------------------------------------------------------------------------------------- 1k ? ? = r ainmax = 6.4 k ?
docid15067 rev 2 27/45 AN2834 how to get the best adc accuracy 44 3.2.7 source frequency condition vs. source and parasitic capacitors the external capacitance will not allow the anal og input voltage to be exactly the same as v ain if the capacitor is not fully charged by the analog source. if the analog input signal changes, then the analog signal frequency (f ain ) should be such that the time period of this analog signal is at least: 10 r ain (c ain + c p ). t ain = analog signal time period = 1/f ain . we have: ? therefore: ? for example: for r ain = 25 k ? , c ain = 7 pf, c p = 3 pf, this gives: ? ? ? thus, the maximum frequency of the source will be: . so for the above defined source characteristic s (capacitance and resistance), the frequency of the source must not exceed 400 khz, ot herwise the adc conver sion result will be not accurate. figure 26. recommended values for r ain and c ain vs. source frequency f ain t ain 10 r ain c ain c p + ?? ? ? ? f ain 1 10 r ain c ain c p + ?? ? ? --------------------------------------------------------------------- ? f ainmax 1 10 25 10 3 ? 73 + ?? 10 12 ? ? ? ? ---------------------------------------------------------------------------------- = f ainmax 400 khz = 0.1 1 10 100 1000 0.01 0.1 1 10 max. r ain (k  ) f ain (khz) c ain 10 nf c ain 22 nf c ain 47 nf ai15489
how to get the best adc accuracy AN2834 28/45 docid15067 rev 2 3.2.8 temperature-effect compensation one method would be to fully characterize t he offset and gain drift and provide a lookup table in memory to correct measurement accord ing to temperature change. this calibration involves additional cost and takes time. the second method consists in recalibrating the adc when the temperature change reaches given values, by using the internal temperature sensor and the adc watchdog. 3.2.9 minimizing injection current check the application to verify whether any digi tal or analog input voltage can be less than v ss or v ssa . if it is the case, a negative injection cu rrent will flow from the pins. the effect on the accuracy will be greater if a digital input is close to t he analog input being converted. negative current injection on any of the standard (non-robust) analog input pins should be avoided as this would significantly reduce th e accuracy of the conversion being performed on another analog input. it is recommended to connect a schottky diode between v ssa and the i/o pin that can give birth to the negative injection current. the adc accuracy will not be affected by po sitive injection currents within the limits specified for i inj(pin) and i inj(pin) (refer to the appropriate stm32x datasheet, i/o port characteristics section). 3.2.10 minimizing i/o pin crosstalk the noise produced by crosstalk can be reduce d by shielding the analog signal by placing ground tracks across it. figure 27 shows the recommended grounding between signals. figure 27. crosstalk between i/o pins analog in digital i/o stm32 ai15490
docid15067 rev 2 29/45 AN2834 how to get the best adc accuracy 44 3.2.11 emi-induced noise reduction you can reduce emi noise using proper shie lding and layout techniques. the possible sources of emission must be physically sepa rated from the receptors. they can be separated electrically by proper grounding and shielding. shielding technique placing ground tracks alongside s ensitive analog signals provi des shielding on the pcb. the other side of the two-layer pcb should also have a ground plane. this prevents interference and i/o crosstalk affecting the signal. see figure 28 . signals coming from distant locations (like s ensors, etc.) should be connected to the pcb using shielded cable. care should be taken to minimize the length of the paths of these types of signal on the pcb. the shield should not be used to carry the ground reference from the sensor or analog source to the microcontroller. a separate wire should be used as ground. the shield should be grounded at only one place near the re ceiver such as the analog ground of the microcontroller. grounding the shield at both ends (source and receiver) might lead to the creation of ground loops, with the result of cu rrent flowing through the shield. in this case, the shield acts like an antenna and the purpose of the shielding is lost. the shielding concept also applie s to grounding the chassis of t he application if it is metallic. and it also helps remove emi and emc interferen ce. in this case the mains earth ground is used to shield the chassis. similarly dc gr ound can be used for shielding in case of the earth ground not being available. figure 28. shielding technique adc adc ground loop not recommended recommended sensor shielded cable sensor do not ground the shield at both ends ground the shield at the receiver end only ai15491
how to get the best adc accuracy AN2834 30/45 docid15067 rev 2 3.2.12 pcb layout recommendations separating the analog and digital layouts it is recommended to separate the analog and digital circuitry on the pcb (see figure 29 ). this also avoids tracks crossing each other. the tracks carrying digital signals may introduce high-frequency noise in analog signals because of coupling. the digital signals produce high-frequency noise because of fast switching. coupling of a capacitive nature is formed due to the metal connections (tracks) separated by the dielectric provided by the pcb base (glass, ceramic or plastic). it is recommended to use different planes for anal og and digital grounds. if there is a lot of analog circuitry then an analog ground plane is recommended. the analog ground must be placed below the analog circuitry. figure 29. separating the analog and digital layouts separating the analog- and digital-circuit power supplies it is desirable to have separate analog and digital power supplies in cases where there is a lot of analog and digital circuits external to the microcontroller (see figure 30 ). depending on the stm32x package, different analog and digital power supply and ground pins are available. the v dda /v ref+ and v dd pins can be powered from separate power supplies. if you use a switching-type power supply for the digital circuitry, you should use a separate linear supply for the analog circuit. also, if you expect a lot of noise on the dc power supply due to i/o switching etc., it is preferable to use a separate supply for the analog circuit. figure 30. separating the analog and digital supplies digital circuitry analog circuitry stm32 power supply analog ground digital ground plane plane (noise generator) (affected by noise) ai15492 v dda v ref+ v ssa stm32 v ref- v dd vout1 vout2 gnd v ss smps linear regulator analog circuit star network ai15493
docid15067 rev 2 31/45 AN2834 how to get the best adc accuracy 44 it is also recommended to connect the analog and digital grounds in a star network. this means that you must connect the analog and digital grounds at only one point. this prevents the introduction of noise in the analog power supply circuit due to digital signal switching. this also prevents current surges from affecting the analog circuit. using separate pcb layers for the supply and ground ? two-layer pcbs for two-layer pcbs, it is recommended to provide a maximum ground plane area. the power supply (v dd , v dda ) should run through thick tracks. the two layers can have their ground shorted together via multiple c onnections in the overlap region if the two layers feature the same ground signals. the unused pcb area can be used as the ground plane. the other convention is to connect the unus ed pcb area on one layer to the positive supply (v dd ) and the unused area on the other layer, to ground. the advantage is a reduced inductance for power and ground signals. the maximum ground area provided for ground on the pcb results in a good shielding effect and reduces the electromagnetic induction su sceptibility of the circuit. ? multilayer pcbs wherever possible, try to use multilayer pc bs and use separate layers on the pcb for power and ground. the v dd and v ss pins of the various ics can be directly connected to the power planes, thus reducing the leng th of track needed to connect the supply and ground. long tracks have a high indu ctive effect. the analog ground can be connected at one point to this ground plan e. if so, it should be close to the power supply. a full ground plane provides good shielding and reduces the electromagnetic induction susceptibility of the circuit. ? single-layer pcbs single-layer pcbs are used to save cost. they can be used only in simple applications when the number of connection s is very limited. it is re commended to fill the unused area with ground. jumpers can be used to connect different parts of the pcb. 3.2.13 component placement and routing place the components and route the signal traces on the pcb so as to shield analog inputs. components like resistors and capacitors must be connected with very short leads. you can use surface-mounted device (s md) resistors and capacitors. you can place smd capacitors close to the microcontrolle r for decoupling purposes. use wide tracks for power, otherwise the series resistance of the tracks would cause a voltage drop. indeed, narrow power tracks have a non-negligible finite resistance, so that high load currents through them would cause a voltage drop across them. quartz crystals must be surrounded by ground tracks/plane. the other side of the two-layer pcb below the crystal should preferably be covered by the ground plane. most crystals have a metallic body that should be grounded. you should also place the crystal close to the microcontroller. you can use a surface-mounted crystal.
how to get the best adc accuracy AN2834 32/45 docid15067 rev 2 3.3 software methods to improve precision ? averaging samples: ? averaging decreases speed but can give improved accuracy ? digital filtering (50/60 hz suppression from dc value) ? set proper sampling frequency (the trigge r from timer is useful in this case) ? perform software post-processing on samp led data (e.g.: comb filter - for 50 hz noise and its harmonics suppression) ? fast fourier transform (fft) for ac measurements: ? to show harmonic parts in measured signal ? slower, due to the use of more computation power ? calibration of adc: offset, gain, bit weight calibration ? decreases internal adc errors ? internal adc structure must be known ? minimizing internal noise generated by cpu ? design firmware to use minimum disturbance from microcontroller during adc conversion - digital silence. 3.3.1 averaging samples the principle of this method is to increase adc precision but decrease adc conversion speed (oversampling). if the measured analog signal produces unstable adc values, then the mean value of the given input signal can be obtained by averaging a set of values. variation can be caused by signal noise or noi se generated by the microcontroller itself (high speed digital signals capacitively coupled to the analog input signal). averaging is performed by choosing an appr opriate number of samples to be averaged. this number depends on the required precision, minimum conversion speed and the level of other adc errors (if another error has a greater influence on adc precision, then increasing the number of averaging values has no effect on total measurement precision). the advantage of this method is improving precision without any hardware changes. the disadvantage is lower conversion speed and th erefore also lower frequency response (it is equivalent to decreasing effective sampling frequency). 3.3.2 digital signal filtering this method uses digital signal processing techniques. in principle, averaging is also a simple digital filter with a specific frequency response. but if the noise frequency spectrum is known, a digital filter can be designed which minimizes noise influence and maximizes adc frequency re sponse. for example, if the noise in the measured signal is coming from the 50hz power lines, then an appropriate digital filter suppresses only the 50 hz frequency and delivers data signal without this noise. the disadvantage of this method is that it needs appropriate microcontroller processing power and resources: cpu speed, data/program memory usage.
docid15067 rev 2 33/45 AN2834 how to get the best adc accuracy 44 3.3.3 fft for ac measurement in some specific cases the application needs to know the amplitude of an ac signal with a given frequency. in this case the effective value of an ac signal can also be obtained by using a relatively slow sampling speed (in comparison to the measured signal frequency). for example, when measuring an ac mains si gnal (which is near-to-sinusoidal and has relatively low harmonics conten t), it is sufficient to choose a sampling frequency 32 times greater than the mains frequency (50 hz). in this case you can obtain harmonics of up to the 15th order. the amplitude of 15th harmonics in the main signal is very small (the next order harmonics can be neglected). the calculated effective value of the mains signal is obtained with high precision because the effective values of harmonics are added to the total ac harmonic value as: so if the 15th harmonics amplitude is only 1% (0.01) from the 1st harmonics (50 hz) then its contribution to the total effe ctive value will be only 0.01% (b ecause of theabove equation - square addition: 0.01 2 = 0.0001). the principle of this method is therefore to sample the ac signal with a known frequency and then perform post-processing onthe fft for each measured period. because the number of sampling points per measured signal period is small (32 points for example) then the performance needed for fft processing is no t so high (only 32-point fft for example). advantages: this method is good for ac measurement of signals with lower distortion. ? the disadvantage is the requirement for precise signal sampling: ? the frequency of the measured signal must be known and the adc sampling frequency must be set exactly as a 2 n multiplier of the measured frequency. ? the input signal frequency is measured by another method. ? the adc sampling frequency is tuned by programming the prescaler and mcu master clock selection (if sampling is performed with an inaccurate clock an interpolation can be used to obtain samples at the required points). u ef u 1 2 u 2 2 ? u n 2 +++ =
how to get the best adc accuracy AN2834 34/45 docid15067 rev 2 3.3.4 adc calibration this method requires knowledge of internal adc structure and how the adc converter is implemented inside the microcontroller. this kn owledge is necessary in order to design a physical/mathematical model of the adc implementation. a proper physical model (which is usually a schematic diagram) is used as the base for describing it mathematically. from the mathem atical model, each element in the model can be obtained by a set of equations (for example, resistor/capacitor values which represent bit weights). to solve these equations, it is necessary to perform a set of practical measurements and obtain a set of solvable equations. from the measured values and mathematical co mputation of the model, all known values of model elements (resistors, voltages, capacitors,...) can be put into the schematic diagram. so instead of the adc schematic with the de signed values, you obtain an adc schematic with the real values for a given microcontroller. computed model parameters are stored in the microcontroller memory after calibration and used in post-processing to correct adc values. 3.3.5 minimizing internal cpu noise when the cpu operates, it generates a lot of in ternal and external signal changes which are transferred into the adc peripheral through capa citive coupling. this disturbance influences adc precision (unpredictable noise due to different microcontroller operations). to minimize influences of the cpu (and of ot her peripherals) on adc, it is necessary to minimize digital signal changes during sampling a nd conversion time (digital silence). this is done using one of the following methods (applied during sampling and conversion time): ? minimizing i/o pin changes ? minimizing internal cpu changes (cpu stop, wait mode) ? stopping clock for unnecessary peri pherals (timers, communications...)
docid15067 rev 2 35/45 AN2834 how to get the best adc accuracy 44 3.4 high impedanc e source measurement this section describes the adc measurement behavior of stm32x adc when a signal source with high internal impedance is used. it explains how to design an application to reach the requested precision and provides workarounds. 3.4.1 adc input stage problem the adc in stm32x devices is a switched-cap acitor adc type. switched capacitors work also as sampling capacitors (see section 1.1 for a detailed explanation). when a signal comes from a voltage source with high internal impedance (for instance, 150 k ? ), an added error can be seen in measurement results. error signals have also been observed on the adc input pin, as shown in figure 33 (if the voltage source has zero voltage: u in = 0 v, r in = 150 k ? , c ext = 0 pf): figure 31. typical voltage source connection to adc input figure 32. noise observed on adc input pin during adc conversions adc input ai17903 stm32 u in r in c ext adc input signal during conversion: an adc noise is injected to the input. ai17904
how to get the best adc accuracy AN2834 36/45 docid15067 rev 2 3.4.2 explanation of the behavior the explanation of this added pin noise and added measurement error (in case a signal source with high internal impedance is used) comes from the internal adc structure: its input sampling circuit. figure 33 shows a simplified schematic of the input stage (sample and hold circuit). figure 33. adc simplified schematic of input stage - sample and hold circuit the spikes (noise) present on adc input pin during conversions are related to the sampling switch (s1). if the switch is closed, some charge (coming from the sample and hold capacitor c sh or caused by another effect) is transferred to the input pin. then this charge starts discharging through the source impedance (r in ). the discharge process ends at the end of the sampling time (t s ) when the switch s1 is opened. the remaining undischarged voltage remains on the capacitor c sh and adc measures this voltage. if the sampling time (t s ) is too short, the remaining voltage does not drop under 0.5 lsb and adc measurement shows an added error. figure 34 shows this process. figure 34. adc input pin noise spikes from internal charge during sampling process note that a non-zero external capacitance c ext (parasitic pin capacitance) also exists, so during conversion time the pin capacitanc e is discharged through source impedance r in . adc input s 1 c sh ai17905 sampling time (t s ) = discharging time conversion time (t c ) added error uinput t ai17906
docid15067 rev 2 37/45 AN2834 how to get the best adc accuracy 44 3.4.3 minimizing added errors workaround for high impedance sources to solve the added error problem, you can increase the sampling time (t s ) configuring adc settings in mcu firmware, so that you discharge the c sh charge through the source impedance r in . the time constant (r in * c sh ) is the reference for choosing the sampling time. to choose the sampling time cycles, use th is formula (for max. error of 1/2 lsb, see also section 3.2.6 ): the clock for adc (f adc ) is another important factor; slowing down the adc clock increases the sampling time. figure 35. effect of sampling time extension if the maximum register value of the sampling time (t s ) setting is reached and the problem is still present, you need a more complex solution whic h is applicable also for measurements of source with extra high internal impedance (see the section workaround for extra high impedance sources below). note that for this application you must take into account not only the internal sampling capacitance, but also any external parasitic capacitance (in parallel to c ext ), such as: pin capacitance, pcb path capacitance, etc. do not add any external capacitor (c ext ) to the input pin when applying this above workaround. its capacity will increase the timing constant (r in * c sh || c ext ) and the problem will remain. t s f adc r in c sh ? ?? 2 n1 + ?? ln ?? ? cycles ?? original sampling time (t s ) time (t s ) conversion time (t c ) original added error u input t extended sampling added error < 0.5 lsb ai17907
how to get the best adc accuracy AN2834 38/45 docid15067 rev 2 workaround for extra high impedance sources this workaround consists of 2 parts: a hardware change and a software change. hardware change: the hardware change consists of adding a large external capacitor (c ext ) to the input pin. the capacity size connected to the input pin must reach the value that causes the discharging of the internal sampling capacity c sh to the external capacitor c ext without increasing the voltage on c ext to more than 0.5 lsb. ? example: ? if the internal capacitor (c sh = 16 pf) is charged to full scale (u max , which corresponds to 4096 lsb), then the external capacitor c ext must be charged at maximum 0.5 lsb voltage level (u lsb ) after discharging c sh to it. the capacity of c ext will then be: the closest larger standard value chosen here is: c ext = 150 nf. if the internal sampling capacitor c sh is not charged to full voltage range (4096 level) before sampling, you can calculate the c ext value replacing ?4096? in the formula above. calculating with 4096 level gives precise measur ement results also in the case of adc input channels switching (c sh was charged from different adc input in the previous measurement). a side effect of this hard ware workaround is the cyclical charging of c ext which must be taken into account. each adc conversion transfers charge from c sh to c ext . one transfer charges the c ext below 0.5 lsb, as described above, but more transfers can charge c ext to larger values if it is not di scharged between two conversions. figure 36 shows an example of this scenario where the adc measurement is performed faster. figure 36. charging the external capacitor with too short time between conversions c ext c sh u max u lsb ------------- - ? ? 16pf 4096 0.5 ------------ - 131nf ? ? = uinput t added error < 0.5 lsb added error > 0.5 lsb too short t c recommended t c ai17908
docid15067 rev 2 39/45 AN2834 how to get the best adc accuracy 44 software change: the side effect mentioned above can be solved by software. the objective is to create a delay in order to let c ext discharge through r in (not measure so often) giving enough ?discharge time? between adc conv ersions. the ?discharge time? (t c ) is equal to the transferred charge from c sh to c ext (charging) and from c ext to r in (discharging). the assumption is that c ext >> c sh . ? where: ? u lsb ....... 0.5 lsb voltage level ? u max ..... 4096 lsb voltage level (worst case) ? q charging = q discharging simplification of the above formula gives the final formula for the required waiting time between conversions: this final formula shows dependency between the external capacitor c ext and the required waiting time between two conversions if the precision u lsb is needed. from the same formula you can see that the argument in logarithm must be positive and therefore there is a condition for the minimal value of c ext : choosing a larger c ext decreases more the time between conversions (t c ). an extra large c ext (c ext >> ) enables sampling more often. however, increasing c ext limits the frequency bandwidth of measurement signal (increasing the ?external? timing constant r in . c ext ). q ch ing arg q sh c sh u max ? == q disch ing arg u lsb r in ---------- - e t r in c ext ------------------- ? t d 0 t c ? ? = c sh u max ? u lsb r in ---------- - e t r in c ext ------------------- t d 0 t c ? ? = t c r in c ext ? ?? ? in 1 c sh c ext ----------- u max u lsb ------------- - ? ? = 1 c sh c ext ----------- u max u lsb ------------- - ? 0 ? ----------- u max u lsb ------------- - ? ------------- - ? ? ------------- - ?
how to get the best adc accuracy AN2834 40/45 docid15067 rev 2 the formulas below show how to choose the optimal c ext value: signal bandwidth in correlation with sample time. signal bandwidt h is characterized by an ?external? timing constant, so optimal so lution is to charge c ext during t c : after simplification we obtain the final formula for optimal c ext : and the corresponding waiting time between conversions: practically the firmware must not program the adc in continuous mode but only in single mode and must ensure that there will be a time gap be tween conversions with duration equal to t c . this adding of waiting time is the software change which must be applied together with the hardware change (adding an external capacitor c ext ). without implementation of t c waiting time in soft ware (for instance, running a conversion just after the first one) the external capacitor c ext will be cyclically charged from the c sh capacitor. after a lot of cycles the voltage on c ext will reach a quite high error value (as previously shown in figure 36 ). a practical example of implementatio n for stm32l1xx adc is shown below: c sh = 16 pf ..... adc property r in = 150 k ..... signal source property u max = 4096 lsb ..... adc property u lsb = 0.5 lsb ..... required precision r in c ext ? ?? t c = r in c ext ? ?? r in c ext ? ?? ? in 1 c sh c ext ----------- u max u lsb ------------- - ? ? = 1 ? in 1 c sh c ext ----------- u max u lsb ------------- - ? = e 1 ? 1 c sh c ext ----------- u max u lsb ------------- - ? = c ext c sh u max u lsb ------------- - 1e 1 ? ? ------------------------ 158 ? c sh u max u lsb ------------- - ? ? = t c r in c ext ? ?? ? in 1 1 158 ? ------------ - ? ? r in c ext ? ?? ?? ? ? c sh u max u lsb ------------- - ? 158 ? 16pf 4096 0.5 ------------ - ?? 207nf 220nf ? ? == t c r in c sh ? ?? ? in 1 c sh c ext ---------- - u max u lsb ------------- - ? ? 150k ? 220nf ? ?? ? in 1 16pf 220nf ----------------- 4096 0.5 ------------ - ? ? 29891 ? s30ms ? ? ==
docid15067 rev 2 41/45 AN2834 how to get the best adc accuracy 44 3.4.4 source of described problem - adc design the following sections list some possible causes for the charging of the internal sampling capacitor c sh . this is not an exhaustive list; only the main possible sources of the adc design are listed. parasitic switch capacitance effect the sampling switch inside adc sampling circuit (see figure 33 ) is not ideal. in reality the sample and hold switch (s1) is designed as 2 transistors (pmos and nmos, see figure 37 ): figure 37. implementation of sampling switch the switch is controlled by the gate voltages of transistors (inverted signal on pmos transistor). this design is a standard bidirecti onal switch (for rail to rail range of input u in voltages). both transistor s have parasitic capacitances between gate and source. if those capacitances are charged (close to the switch), then their charge can be transferred to the sampling capacitor (see figure 38 ). figure 38. parasitic capacitances of sampling switch this charging and discharging currents (pmos and nmos asymmetric capacitances) can cause charge transfer to sampling capacitor csh. h = switch on l = switch off c sh s 1 u in ai17909 c sh s 1 u in c ext i i l --> h switching on ai17910
how to get the best adc accuracy AN2834 42/45 docid15067 rev 2 internal charging of sampling capacitor it is possible that after the conversion process (successive approximation process in sar type of adc) the sample and hold capacitor c sh is charged to some voltage. the reason can be: ? some leakage current to c sh (parasitic current insi de adc structure, see figure 39 ) ? residual charge transfer from the switches when adc structure is switched back to default state before next conversion ? other reasons (related to intern al adc parasitic structures) figure 39. parasitic current ex ample inside adc structure c sh s 1 r parasitic adc input ai17911
docid15067 rev 2 43/45 AN2834 conclusion 44 4 conclusion this application notes describes the main adc errors and then methods and application design rules to minimize stm32x adc errors and obtain the best adc accuracy. the choice of method depends on the application requirements and is always a compromise between speed, precision, eno ugh computation power and design topology. the published methods lead to a precision improvement and are optimized for the design of an adc converter using the sar (successi ve approximation register) principle.
revision history AN2834 44/45 docid15067 rev 2 5 revision history table 2. document revision history date revision changes 14-nov-2008 1 initial release. 16-sep-2013 2 extended to stm32fx series and stm32l1 series devices. added section 1.1: sar adc internal structure . added section 3.4: high impedance source measurement . added section 3.3: software methods to improve precision . text improvements and additions. changed the disclaimer on the final page.
docid15067 rev 2 45/45 AN2834 45 ? please read carefully: information in this document is provided solely in connection with st products. stmicroelectronics nv and its subsidiaries (?st ?) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described he rein at any time, without notice. all st products are sold pursuant to st?s terms and conditions of sale. purchasers are solely responsible for the choice, selection and use of the st products and services described herein, and st as sumes no liability whatsoever relating to the choice, selection or use of the st products and services described herein. no license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. i f any part of this document refers to any third party products or services it shall not be deemed a license grant by st for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoev er of such third party products or services or any intellectual property contained therein. unless otherwise set forth in st?s terms and conditions of sale st disclaims any express or implied warranty with respect to the use and/or sale of st products including without limitation implied warranties of merchantability, fitness for a particul ar purpose (and their equivalents under the laws of any jurisdiction), or infringement of any patent, copyright or other intellectual property right. st products are not designed or authorized for use in: (a) safety critical applications such as life supporting, active implanted devices or systems with product functional safety requirements; (b) aeronautic applications; (c) automotive applications or environments, and/or (d) aerospace applications or environments. where st products are not designed for such use, the purchaser shall use products at purchaser?s sole risk, even if st has been informed in writing of such usage, unless a product is expressly designated by st as being intended for ? automotive, automotive safe ty or medical? industry domains according to st product design specifications. products formally escc, qml or jan qualified are deemed suitable for use in aerospace by the corresponding governmental agency. resale of st products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by st for the st product or service described herein and shall not create or extend in any manner whatsoev er, any liability of st. st and the st logo are trademarks or registered trademarks of st in various countries. information in this document supersedes and replaces all information previously supplied. the st logo is a registered trademark of stmicroelectronics. all other names are the property of their respective owners. ? 2013 stmicroelectronics - all rights reserved stmicroelectronics group of companies australia - belgium - brazil - canada - china - czech republic - finland - france - germany - hong kong - india - israel - ital y - japan - malaysia - malta - morocco - philippines - singapore - spain - sweden - switzerland - united kingdom - united states of america www.st.com


▲Up To Search▲   

 
Price & Availability of AN2834

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X